package cn.edu.scau.cmi.lixiaoyuan.client.finalClient;


import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;

import javafx.stage.Stage;
import cn.edu.scau.cmi.lixiaoyuan.client.AbstractFactoryClient;
import cn.edu.scau.cmi.lixiaoyuan.client.AdapterClient;
import cn.edu.scau.cmi.lixiaoyuan.client.ConsistentCompositeClient;
import cn.edu.scau.cmi.lixiaoyuan.client.FactoryClient;
import cn.edu.scau.cmi.lixiaoyuan.client.InterProgrammingClient;
import cn.edu.scau.cmi.lixiaoyuan.client.SafeCompositeClient;
import cn.edu.scau.cmi.lixiaoyuan.client.SimpleFactoryMethodClient;
import cn.edu.scau.cmi.lixiaoyuan.client.SingletonClient;
import cn.edu.scau.cmi.lixiaoyuan.client.hibernate.HibernateDaoClient;
import cn.edu.scau.cmi.lixiaoyuan.client.springHibernate.SpringHibernateClient;
import cn.edu.scau.cmi.lixiaoyuan.multition.Marshal;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class MainController implements Initializable {
   public List<String> list = new ArrayList<String>();

   public static  Thread thread = null;
    
   String str = "";
   
   @FXML
   private Button myButton;

   @FXML
   private TextField myTextField;
   
   @FXML
   private Button mybutton2;

   @FXML
   private TextField myTextField2;
   
   @FXML
   private TextArea myTextarea;
   
   @Override
   public void initialize(URL location, ResourceBundle resources) {

      

   }

   public void showSingleton(ActionEvent event) {
       
     
     
       myTextarea.setText(str);
      
       
   }
   
   public void showSingletonSecond(ActionEvent event) {
       String message = Marshal.getString(myTextField2.getText());
       str = str+message+"\r\n";
       myTextarea.setText(str);
      
       
   }
   
   
   public void openSingleton(ActionEvent event) {
	   SingletonClient singletonC = new SingletonClient();
	   singletonC.start(new Stage());
   }
   
   public void baseCoding(ActionEvent event) {
	   InterProgrammingClient.main(null);
   }
   
   public void openSingleFactory(ActionEvent event) {
	   SimpleFactoryMethodClient singleFactoryClient = new SimpleFactoryMethodClient();
	   singleFactoryClient.main(null);
   }
   
   public void openFactoryClient(ActionEvent event) {
	  
		       thread=null;
	           thread = new Thread(){
	          public void run() {
			   FactoryClient fc = new FactoryClient();
			   fc.main(null);
	           
	           }
	          };
	           thread.start();
	           
   }
   
   public void openAbstractFactoryClient(ActionEvent event) {
	   Thread thread = new Thread() {
		   public void run() {
			   AbstractFactoryClient ac = new AbstractFactoryClient();
			   ac.main(null); 
		   }
	   
	   };
	   thread.start();
   }
   
   
   public void openAdapterClient(ActionEvent event) {
	   AdapterClient ac = new AdapterClient();
	  ac.start(new Stage());
   }
   
   public void openConsistentCompositeClient(ActionEvent event) {
	   thread=null;
       thread = new Thread(){
       public void run() {
    	  ConsistentCompositeClient cc = new ConsistentCompositeClient();
	   cc.main(null);
       
       }
      };
       thread.start();
       
}
   
   public void openSafeCompositeClient(ActionEvent event) {
	   thread=null;
       thread = new Thread(){
       public void run() {
    	   SafeCompositeClient sc = new SafeCompositeClient();
	   sc.main(null);
       
       }
      };
       thread.start();
       
}
   
   
   public void openHibernateDaoClient(ActionEvent event) {
	   thread=null;
       thread = new Thread(){
       public void run() {
    	   HibernateDaoClient sc = new HibernateDaoClient();
	   try {
		sc.main(null);
	} catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
       
       }
      };
       thread.start();
       
}
  
   public void openSpringHibernateClient(ActionEvent event) {
	   thread=null;
       thread = new Thread(){
       public void run() {
    	   SpringHibernateClient sc = new SpringHibernateClient();
	   try {
		sc.main(null);
	} catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
       
       }
      };
       thread.start();
       
}
}

